<?php

namespace App\Models\Task\SnapTasks\Repositories;

use App\Models\Task\SnapTasks\Repositories\Interfaces\SnapTaskRepositoryInterface;
use Illuminate\Support\Facades\Cache;

class CountSnapNumberService
{
    private string $cache_key;

    public function __construct()
    {
        $this->cache_key = "count:snap:number";
    }

    public function refreshCount(): void
    {
        $snapRepo = app(SnapTaskRepositoryInterface::class);
        $count    = $snapRepo->countTask();
        $this->setCount($count);
    }

    public function setCount(int $count): void
    {
        Cache::forever($this->cache_key, $count);
    }

    public function getCount(): int
    {
        return Cache::get($this->cache_key) ?: 0;
    }


    public function addCount(): void
    {
        Cache::add($this->cache_key, 1);
    }


}